package net.mikoo.seals.common.result;

import java.util.HashMap;
import java.util.Map;


/**
 * 
 * @author huangxm
 * 
 * @param <T>
 */
public class ResultSupport<T> implements Result<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1802692098484483921L;
	/**
	 * 请不要修改默认值
	 */
	private boolean success = false;

	private String code;

	private String message;

	private T model;

	public String getCode() {
		return code;
	}

	public boolean isSuccess() {
		return success;
	}

	@Override
	public void setModel(T model) {
		this.model = model;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public String getMessage() {
		
		/*if(StringUtils.isNotEmpty(message)){
			return message;
		}
		
		if(StringUtils.isEmpty(code)){
			return message;
		}
		
		try {
			String msg = PropertiesHandler.getInstance("/messages.properties").getProperty(code);
			if(StringUtils.isNotEmpty(msg)){
				return msg;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}*/
		
		return message;
	}

	@Override
	public void setMessage(String message) {
		this.message = message;
	}

	@Override
	public T getModel() {
		return model;
	}
	
	
	public void setResult(boolean success,T model,String code){
		setResult(success,model,code,null);
	}
	
	public void setResult(boolean success,T model,String code,String message){
		this.success = success;
		this.model = model;
		this.code = code;
		this.message = message;
	}
	
	public void setResult(boolean success,String code){
		this.setResult(success, code, null);
	}
	
	public void setResult(boolean success,String code,String message){
		setResult( success,null, code, message);
	}

	@Override
	public Map<String, String> getMapResult() {
		Map<String, String> result = new HashMap<String, String>();
		result.put("code", this.code);
		result.put("message", this.message);
		return result;
	}
}
